#环境 linux
#一键安装rabitmq，在linux环境中使用脚本运行该文件（sh auto_install_rabbitmq.sh）
#!/bin/bash
#功能：rabbitmq自动安装。
#需要将安装文件put到/opt/tools/ 目录下
#然后执行本脚本，安装至/usl/local/目录下。
#默认管理员账户：账号：admin 密码：admin123456

rabbitmq_install(){

#设定ERLANG变量
ERLANG_FILE=otp_src_21.1.tar.gz
ERLANG_FILE_DIR=otp_src_21.1
ERLANG_PATH=/usr/local/erlang

#设定rabbitmq环境变量
RB_FILE=rabbitmq-server-3.6.8
RB_FILE_DIR=/usr/local/
RB_PATH=/usr/local/rabbitmq-server-3.6.8

cd /usr/local/src
#下载安装包
wget http://erlang.org/download/$ERLANG_FILE

#yum安装依赖包
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC-devel

#解压erlang文件并安装
tar -zxvf $ERLANG_FILE
cd $ERLANG_FILE_DIR
./configure --with-ssl --prefix=$ERLANG_PATH
make && make install

#验证erlang是否安装成功
#./bin/erl

#解压rabbitmq
#tar -xvJf $RB_FILE -C $RB_FILE_DIR
wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.8/rabbitmq-server-3.6.8-1.el7.noarch.rpm
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
yum install rabbitmq-server-3.6.8-1.el7.noarch.rpm
cp /usr/share/doc/rabbitmq-server-3.6.8/rabbitmq.config.example /etc/rabbitmq

########写入rabbitmq-env.conf配置文件########
echo '#!/bin/sh
RABBITMQ_MNESIA_BASE=/usr/local/rabbitmq-server/data
RABBITMQ_LOG_BASE=/usr/local/rabbitmq-server/log
' > /etc/rabbitmq/rabbitmq-env.conf

cd /usr/local
mkdir rabbitmq-server
chmod -R 777 /usr/local/rabbitmq-server

#设定erlang/rabbitmq环境变量
#PATH=/opt/app/erlang/bin:$PATH
echo "###erlang/rabbitmq PATH #####" >>/etc/profile
echo "PATH=${ERLANG_PATH}/bin:{}/sbin:$PATH" >>/etc/profile
echo "PATH=${RB_PATH}/sbin:{}/sbin:$PATH" >>/etc/profile
echo "export PATH " >>/etc/profile
echo "###erlang PATH END ### ">>/etc/profile

#刷新配置文件
source /etc/profile

systemctl start rabbitmq-server.service
#添加到启动项并设置开机自启
chkconfig rabbitmq-server on
systemctl enable rabbitmq-server.service
#开启管理界面
rabbitmq-plugins enable rabbitmq_management
#设置账号
rabbitmqctl add_user admin admin123456
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
}

read -p " Do you want to install rabbitmq:Y/N " REDISCONFIRM
if [ "$REDISCONFIRM" = "Y" ] || [ "$REDISCONFIRM" = "y" ];then
rabbitmq_install
else
echo "=================== install the next thing =============="
fi#环境 linux
#一键安装rabitmq，在linux环境中使用脚本运行该文件（sh auto_install_rabbitmq.sh）
#!/bin/bash
#功能：rabbitmq自动安装。
#需要将安装文件put到/opt/tools/ 目录下
#然后执行本脚本，安装至/usl/local/目录下。
#默认管理员账户：账号：admin 密码：admin123456

rabbitmq_install(){

#设定ERLANG变量
ERLANG_FILE=otp_src_21.1.tar.gz
ERLANG_FILE_DIR=otp_src_21.1
ERLANG_PATH=/usr/local/erlang

#设定rabbitmq环境变量
RB_FILE=rabbitmq-server-3.6.8
RB_FILE_DIR=/usr/local/
RB_PATH=/usr/local/rabbitmq-server-3.6.8

cd /usr/local/src
#下载安装包
wget http://erlang.org/download/$ERLANG_FILE

#yum安装依赖包
yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel unixODBC-devel

#解压erlang文件并安装
tar -zxvf $ERLANG_FILE
cd $ERLANG_FILE_DIR
./configure --with-ssl --prefix=$ERLANG_PATH
make && make install

#验证erlang是否安装成功
#./bin/erl

#解压rabbitmq
#tar -xvJf $RB_FILE -C $RB_FILE_DIR
wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.8/rabbitmq-server-3.6.8-1.el7.noarch.rpm
rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
yum install rabbitmq-server-3.6.8-1.el7.noarch.rpm
cp /usr/share/doc/rabbitmq-server-3.6.8/rabbitmq.config.example /etc/rabbitmq

########写入rabbitmq-env.conf配置文件########
echo '#!/bin/sh
RABBITMQ_MNESIA_BASE=/usr/local/rabbitmq-server/data
RABBITMQ_LOG_BASE=/usr/local/rabbitmq-server/log
' > /etc/rabbitmq/rabbitmq-env.conf

cd /usr/local
mkdir rabbitmq-server
chmod -R 777 /usr/local/rabbitmq-server

#设定erlang/rabbitmq环境变量
#PATH=/opt/app/erlang/bin:$PATH
echo "###erlang/rabbitmq PATH #####" >>/etc/profile
echo "PATH=${ERLANG_PATH}/bin:{}/sbin:$PATH" >>/etc/profile
echo "PATH=${RB_PATH}/sbin:{}/sbin:$PATH" >>/etc/profile
echo "export PATH " >>/etc/profile
echo "###erlang PATH END ### ">>/etc/profile

#刷新配置文件
source /etc/profile

systemctl start rabbitmq-server.service
#添加到启动项并设置开机自启
chkconfig rabbitmq-server on
systemctl enable rabbitmq-server.service
#开启管理界面
rabbitmq-plugins enable rabbitmq_management
#设置账号
rabbitmqctl add_user admin admin123456
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
}

read -p " Do you want to install rabbitmq:Y/N " REDISCONFIRM
if [ "$REDISCONFIRM" = "Y" ] || [ "$REDISCONFIRM" = "y" ];then
rabbitmq_install
else
echo "=================== install the next thing =============="
fi